package top.huhuiyu.spirngboot2.total.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import top.huhuiyu.spirngboot2.total.base.BaseDataResult;
import top.huhuiyu.spirngboot2.total.entity.TbFile;
import top.huhuiyu.spirngboot2.total.service.FileService;

import javax.servlet.http.HttpServletResponse;

@RequiredArgsConstructor
@RestController
@RequestMapping("/file")
public class FileController {
    private final FileService fileService;

    @PostMapping("")
    public BaseDataResult<TbFile> upload(TbFile tbFile, MultipartFile file) {
        return fileService.upload(tbFile, file);
    }

    @GetMapping("/{id}")
    public void download(@PathVariable("id") Integer id, HttpServletResponse response) {
        fileService.download(id, response);
    }
}
